<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ page isELIgnored="false"%>
<jsp:include page="frame/header.jsp"></jsp:include>

<title>商家管理</title>

<style>
.pagination .active a {
	/*background-color: #CC0041;
	color:white;*/
}
</style>

</head>

<body>

	<div class="container-fluid">
		<div id="market" class="row-fluid">
			<div>
				<ul class="breadcrumb">
					<li><a href="#">商家管理</a> <span class="divider">/</span></li>
					<li><a href="#">商家列表</a></li>
				</ul>
			</div>

			<div class="box">
				<div class="box-header well" data-original-title>
					<h2>
						<i class="icon-th"></i> 商家信息列表
					</h2>

					<div class="box-icon">
						<a href="#" class="btn btn-setting btn-round"><i
							class="icon-cog"></i></a> <a href="#"
							class="btn btn-minimize btn-round"><i class="icon-chevron-up"></i></a>
						<a href="#" class="btn btn-close btn-round"><i
							class="icon-remove"></i></a>
					</div>
				</div>
				<div class="box-content">
					<div id="search-form">
						<form id="searchForm" method="post" class="form-search span12" action="<c:url value="/seller/search_seller"/>">
							<input type="hidden" name="pageNum" id="pageNum" value="${searchForm.pageNum }">
							<input type="hidden" name="sellerId" id="sellerId" value="0">
							<input type="text" name="search" id="searchText" value="${searchForm.search }" 
								class="input-meidum search-query" placeholder="输入关键词:商家名、地址、电话等">
							
							<select id="foodType" class="input-meidum" name="foodType"
								check-type="required" required-message="请选择所属菜系">
								<option value="0">全部</option>
								<c:forEach var="foodType" items="${foodTypes }">
									<option value="${foodType.typeId }"
										<c:if test="${searchForm.foodType == foodType.typeId}">selected</c:if>>
										${foodType.typeName}</option>
								</c:forEach>
							</select>
							<button type="button" id="searchBtn" class="btn">&nbsp;&nbsp;搜索&nbsp;&nbsp;</button>
							<button type="button" id="newBtn" class="btn btn-danger pull-right">新增商家</button>
						</form>

					</div>
					<table id="userInfo" class="table table-striped table-bordered ">
						<thead>
							<tr>
								<th width="30">序号</th>
								<th >商家名称</th>
								<th >地址</th>
								<th >联系电话</th>
								<th >手机号</th>
								<th >所属菜系</th>
								<th >所属用户</th>
								<th width="50">操作</th>
							</tr>
						</thead>
						<tbody>
							<c:forEach var="seller" items="${pageModel.result }" varStatus="status">
								<tr>
									<td>${status.index+1 }</td>
									<td>${seller.sellerName }</td>
									<td>${seller.address } </td>
									<td>${seller.tel } </td>
									<td>${seller.phone }</td>
									<td>${seller.foodTypeName }</td>
									<td>${seller.username }</td>
									
									<td><a href="javascript:edit('${seller.sellerId }')"><i
											class="icon-edit"></i></a> &nbsp;&nbsp; <a
										href="javascript:del('${seller.sellerId }')"><i class="icon-minus"></i></a></td>
								</tr>
							</c:forEach>
						</tbody>
					</table>
					
					<div id="mypager" class="mypager"></div>
				</div>
			</div>
		</div>
		<!--/fluid-row-->

	</div>
	<!--/.fluid-container-->

	<jsp:include page="frame/scripts.jsp"></jsp:include>
	<script type="text/javascript">
	
	var pageNum = "${pageModel.pageNum}";
	var totalPage = "${pageModel.totalPage}";
	var numPerPage = "${pageModel.numPerPage}";
	
	$(document).ready(function(){
		
		$("#newBtn").click(function(){
			//跳转至新增页面
			window.location.href = '<c:url value="/seller/addSeller" />';
		})
		
		$('#mypager').bootstrapPaginator({
			currentPage:pageNum,
			totalPages:totalPage,
			numberOfPages:numPerPage,
			onPageClicked:function(event, originalEvent, type,page){
				$("input[name='pageNum']").val(page);
				$("#searchForm").submit();
			}
		});
		
		
		$('#searchBtn').click(function(){
			$("#searchForm").submit();
		})
		
		$("#foodType").change(function(){
			$("#searchForm").submit();
		})
	})
	
	function edit(sellerId){
		window.location.href = '<c:url value="/seller/editSeller?sellerId='+sellerId+'"/>';
	}
	
	function del(sellerId){
		if(confirm("确定要删除吗？")){
			$("input[name='sellerId']").val(sellerId);
			$("#searchForm").submit();
		}
	}
	</script>
</body>
</html>
